<template>
	<view class="ct-parent">
		<view class="list-item" style="margin-top: 20rpx;" @click="changeName">
			<text class="list-item-title">家谱名称</text>
			<text class="list-flex-view"></text>
			<text class="list-item-content">{{jiapuName}}</text>
			<image class="list-item-arrow" src="../../static/right-arrow.png"></image>
		</view>
		<view class="line"/>
		<view class="list-item" @click="changeAddress">
			<text class="list-item-title">所属地区</text>
			<text class="list-flex-view"></text>
			<text class="list-item-content">{{address}}</text>
			<image class="list-item-arrow" src="../../static/right-arrow.png"></image>
		</view>
		<view class="line"/>
		<view class="list-item" @click="changeDesc">
			<text class="list-item-title">家谱简介</text>
			<text class="list-item-title" style="color: #585858;font-size: 24rpx;margin-left: 10rpx;margin-top: 10rpx;">(选填)</text>
			<text class="list-flex-view"></text>
			<text class="list-item-content">{{jiapuDesc}}</text>
			<image class="list-item-arrow" src="../../static/right-arrow.png"></image>
		</view>
		<text class="tijiao" @click="addTree" >完成</text>
		<choseAddress :isShow="isChoseAddressShow" @returnAddress="addressReturn"></choseAddress>
		<inputDalog :isShow="isShowNamePop" :dataSource="nameData" @returnInputDialog="inputDialogReturn"></inputDalog>
		<inputJiaPuDescDalog :isShow="isShowDescPop" dataSource="请填写家谱简介" @returnInputDesc="inputDialogReturn"></inputJiaPuDescDalog>
		<LoginTipDialog :isShow="isShowLoginTip" dataSource="登录查看具体信息"  @returnLoginTipDialog="returnLoginTipDialog"/>
	</view>
</template>

<script>
	import inputDalog from '../../components/input-dialog/input-dialog.vue'
	import choseAddress from '../../components/chose-address/chose-address.vue'
	import LoginTipDialog from "@/components/login-tip-dialog/login-tip-dialog.vue";
	import inputJiaPuDescDalog from "@/components/input-jiapu-desc-dialog/input-jiapu-desc-dialog.vue";
	import request from '../index/request.js';
	export default {
		components: {
			choseAddress,inputDalog,LoginTipDialog,inputJiaPuDescDalog
		},
		data() {
			return {
				jiapuName:"",
				address:"请选择",
				jiapuDesc:"",
				isShowNamePop:false,
				isShowDescPop:false,
				isChoseAddressShow:false,
				isShowLoginTip:false,
				nameData:{
					title:"家谱名称",
					hint:"请填写家谱名称",
					leftTxt:"取消",
					rightTxt:"确认",
					tag:"name",
					maxlength:8
				},
			}
		},
		methods: {
			onShow: function (options) {
				this.share.url= '/pages/tabBar/home/index?appInviteId='+this.appUtil.getAppInviteId()
				this.share.shareType=1
				this.loginState()
			},
			onLoad: function (options) {
				this.appUtil.saveAppInviteId(options)
			},
			loginState:function(){
				var user = uni.getStorageSync("shiqin-user")
				if (!user.PQD) {
					this.isShowLoginTip=true
				}
			},
			
			inputDialogReturn:function(event){
				this.isShowNamePop=event.isclose
				this.isShowDescPop=event.isclose
				if(event.inputStr){
					if(event.tag=='name'){
						this.jiapuName=event.inputStr
					}else if(event.tag=='desc'){
						this.jiapuDesc=event.inputStr
					}
				}
			},
			returnLoginTipDialog:function(e){
				this.isShowLoginTip=e.isclose
				if(e.tag){
					uni.navigateTo({
						url:"../index/index"
					})
				}
			},
			addressReturn:function(e){
				this.isChoseAddressShow=e.isclose
				if(e.address){
					this.address=e.address
				}
			},
			changeName:function(){
				this.isShowNamePop=true
			},
			changeAddress:function(){
				this.isChoseAddressShow=true
			},
			changeDesc:function(){
				this.isShowDescPop=true
			},
			addTree:function(){
				if(this.loginState()){
					return
				}
				var user = uni.getStorageSync("shiqin-user")
				if(!user.PQD){
					this.isShowLoginTip=true
					return
				}
				if(this.jiapuName==''){
					uni.showToast({
						title:"请填写家谱名称",
						duration:2000,
						icon:"none"
					})
					return
				}
				if(this.address=='请选择'){
					uni.showToast({
						title:"请选择家谱地址",
						duration:2000,
						icon:"none"
					})
					return
				}
				var that = this
				var user = uni.getStorageSync("shiqin-user")
				request.post("api/common/addpedigree", {
					title:this.jiapuName,
					xingshi:user.nickname,
					area:this.address,
					auth:"1",
					bio:this.jiapuDesc
				}).then(data => {
					uni.$emit("refrashHomeList")
					uni.navigateBack({
					    delta: 2
					});
				})
			}
		}
	}
</script>

<style>
	@import "index.css";
</style>
